package com.taoye.thread;

/**
 * 线程在等待中被调用了interrupt()方法
 *
 * @author : Mr.Tao
 * @version : 1.0
 * @date : 2022/4/4 10:31
 **/
public class Demo39 {
    public static void main(String[] args) throws InterruptedException {
        Object lock = new Object();
        Thread t = new Demo39ThreadA(lock);
        t.setName("A");
        t.start();
        Thread.sleep(2000);
        t.interrupt();
    }
}

class Demo39ThreadA extends Thread {
    private Object lock;

    public Demo39ThreadA(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        synchronized (lock) {
            try {
                System.out.println("我是线程A，现在开始进入等待状态了");
                lock.wait();
                System.out.println("我是线程A，现在等待结束了");
            } catch (InterruptedException e) {
                System.out.println("我是线程A，现在被意外终止等待了");
                e.printStackTrace();
            }
        }

    }
}

